package org.mall.modules.pay.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import lombok.AllArgsConstructor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.alipay.api.AlipayConstants.CHARSET;

/***
 *@author yinxucun
 *@date 2020-01-13 10:39 
 */
@Configuration
@EnableConfigurationProperties(AliPayProperties.class)
@AllArgsConstructor
public class AliPayConfiguration {
    private static String serverUrl="https://openapi.alipay.com/gateway.do";
    private AliPayProperties properties;


    @Bean
    AlipayClient alipayClient(){
        AlipayClient alipayClient = new DefaultAlipayClient(serverUrl, this.properties.getAppId(), this.properties.getAppPrivateKey(),
                "json", CHARSET, this.properties.getAliPayPublicKey(), this.properties.getSignType());

        return alipayClient;
    }
}
